package com.jl.jlapp.mvp.activity;

import android.app.ProgressDialog;
import android.content.Intent;
import android.content.SharedPreferences;
import android.graphics.Bitmap;
import android.icu.text.IDNA;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.RecyclerView;
import android.view.KeyEvent;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.animation.AlphaAnimation;
import android.view.animation.Animation;
import android.view.animation.Animation.AnimationListener;
import android.widget.ImageView;
import android.widget.ImageView.ScaleType;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;
import android.widget.Toast;

import butterknife.BindView;
import butterknife.ButterKnife;

import com.bm.library.Info;
import com.bm.library.PhotoView;
import com.bumptech.glide.Glide;
import com.bumptech.glide.RequestBuilder;
import com.bumptech.glide.RequestManager;
import com.bumptech.glide.request.RequestOptions;
import com.bumptech.glide.request.target.SimpleTarget;
import com.bumptech.glide.request.transition.Transition;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseQuickAdapter.OnItemChildClickListener;
import com.jl.jlapp.R;
import com.jl.jlapp.adapter.AfterSaleDetailGoodsListAdapter;
import com.jl.jlapp.adapter.AfterSaleImgAdapter;
import com.jl.jlapp.eneity.AfterSalePic;
import com.jl.jlapp.eneity.CustomerServiceByUserIdAndOrderIdModel;
import com.jl.jlapp.eneity.CustomerServiceByUserIdAndOrderIdModel.ResultDataBean.AfterSalePicsBean;
import com.jl.jlapp.eneity.CustomerServiceByUserIdAndOrderIdModel.ResultDataBean.OrderTableBean.OrderDetailsBean;
import com.jl.jlapp.nets.Api;
import com.jl.jlapp.nets.CommonObserver;
import com.jl.jlapp.nets.Net;
import com.jl.jlapp.utils.CustomGridLayoutManager;
import com.jl.jlapp.utils.CustomLanearLayoutManager;

import io.reactivex.Flowable;
import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.schedulers.Schedulers;

import java.util.ArrayList;
import java.util.List;

public class AfterSaleDetailActivity
        extends AppCompatActivity {
    AfterSaleImgAdapter afterSaleImgAdapter;
    ArrayList<AfterSalePic> afterSaleImgList;
    List<CustomerServiceByUserIdAndOrderIdModel.ResultDataBean.AfterSalePicsBean> afterSalePicsBeanList = new ArrayList();
    @BindView(R.id.back)
    ImageView back;
    AfterSaleDetailGoodsListAdapter goodsListAdapter;
    @BindView(R.id.imgRecyclerView)
    RecyclerView imgRecyclerView;
    AlphaAnimation in = new AlphaAnimation(0.0F, 1.0F);
    @BindView(R.id.bg)
    ImageView mBg;
    Info mInfo;
    @BindView(R.id.img)
    PhotoView mPhotoView;
    @BindView(R.id.name)
    TextView name;
    List<CustomerServiceByUserIdAndOrderIdModel.ResultDataBean.OrderTableBean.OrderDetailsBean> orderDetailsBeanList = new ArrayList();
    int orderId = -1;
    AlphaAnimation out = new AlphaAnimation(1.0F, 0.0F);
    @BindView(R.id.parent_detail)
    LinearLayout parentDetail;
    @BindView(R.id.parent_photo_view)
    RelativeLayout parentPhotoView;
    @BindView(R.id.phone)
    TextView phone;
    @BindView(R.id.pic_sc)
    TextView picSc;
    @BindView(R.id.problem_description)
    TextView problem_description;
    private ProgressDialog progressDialog;
    @BindView(R.id.recyclerView)
    RecyclerView recyclerView;
    @BindView(R.id.service_type)
    TextView service_type;
    @BindView(R.id.status)
    TextView status;
    int userId = -1;

    private void init() {
        getNetData();
        imgSetAdapter();
        this.back.setOnClickListener(new OnClickListener() {
            public void onClick(View paramAnonymousView) {
                AfterSaleDetailActivity.this.finish();
            }
        });
        this.mPhotoView.setScaleType(ScaleType.CENTER_INSIDE);
        this.in.setDuration(300L);
        this.out.setDuration(300L);
        this.out.setAnimationListener(new AnimationListener() {
            public void onAnimationEnd(Animation paramAnonymousAnimation) {
                AfterSaleDetailActivity.this.mBg.setVisibility(View.INVISIBLE);
            }

            public void onAnimationRepeat(Animation paramAnonymousAnimation) {
            }

            public void onAnimationStart(Animation paramAnonymousAnimation) {
            }
        });
        this.mPhotoView.enable();
        this.mPhotoView.setOnClickListener(new OnClickListener() {
            public void onClick(View paramAnonymousView) {
                AfterSaleDetailActivity.this.mBg.startAnimation(AfterSaleDetailActivity.this.out);
                AfterSaleDetailActivity.this.mPhotoView.animaTo(AfterSaleDetailActivity.this.mInfo, new Runnable() {
                    public void run() {
                        AfterSaleDetailActivity.this.parentPhotoView.setVisibility(View.GONE);
                        AfterSaleDetailActivity.this.parentDetail.setVisibility(View.VISIBLE);
                    }
                });
            }
        });
    }

    public void buildProgressDialog() {
        if (this.progressDialog == null) {
            this.progressDialog = new ProgressDialog(this);
            this.progressDialog.setProgressStyle(0);
        }
        this.progressDialog.setMessage("加载中");
        this.progressDialog.setCancelable(true);
        this.progressDialog.show();
    }

    public void cancelProgressDialog() {
        if ((this.progressDialog != null) && (this.progressDialog.isShowing())) {
            this.progressDialog.dismiss();
        }
    }

    public void getNetData() {
        if ((this.orderId != -1) && (this.userId != -1)) {
            Net.get().getCustomerServiceByUserIdAndOrderId(this.orderId, this.userId).subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread())
                    .subscribe(new CommonObserver<CustomerServiceByUserIdAndOrderIdModel>() {
                        @Override
                        protected void onError(String errorMsg) {

                        }

                        @Override
                        protected void onSuccess(CustomerServiceByUserIdAndOrderIdModel customerServiceByUserIdAndOrderIdModel) {

                        }
                    });
        }

        if (this.userId == -1) {
            startActivity(new Intent(this, LoginActivity.class));
            return;
        }

        if (this.orderId != -1)
            Toast.makeText(this, "页面传值没有接收到", Toast.LENGTH_SHORT).show();
    }

    public void imgSetAdapter() {
        this.imgRecyclerView.setLayoutManager(new CustomGridLayoutManager(this, 5, false));
        this.afterSaleImgAdapter = new AfterSaleImgAdapter(R.layout.after_sale_img_item, this.afterSalePicsBeanList);
        this.imgRecyclerView.setAdapter(this.afterSaleImgAdapter);
        this.afterSaleImgAdapter.setOnItemChildClickListener(new OnItemChildClickListener() {
            public void onItemChildClick(BaseQuickAdapter paramAnonymousBaseQuickAdapter, View paramAnonymousView, int paramAnonymousInt) {

                String picUrl = ((CustomerServiceByUserIdAndOrderIdModel.ResultDataBean.AfterSalePicsBean) AfterSaleDetailActivity.this.afterSalePicsBeanList.get(paramAnonymousInt)).getPicUrl();
                AfterSaleDetailActivity.this.parentDetail.setVisibility(View.GONE);
                AfterSaleDetailActivity.this.mInfo = AfterSaleDetailActivity.this.mPhotoView.getInfo();
                Glide.with(AfterSaleDetailActivity.this).asBitmap().apply(new RequestOptions().placeholder(R.drawable.img_lose_xss).error(R.drawable.img_lose_xs)).load("http://117.158.178.202:8001/JLMIS/" + picUrl).into(new SimpleTarget<Bitmap>() {
                    @Override
                    public void onResourceReady(@NonNull Bitmap resource, @Nullable Transition<? super Bitmap> transition) {
                        AfterSaleDetailActivity.this.mPhotoView.setImageBitmap(resource);
                        AfterSaleDetailActivity.this.mBg.startAnimation(AfterSaleDetailActivity.this.in);
                        AfterSaleDetailActivity.this.mBg.setVisibility(View.VISIBLE);
                        AfterSaleDetailActivity.this.parentPhotoView.setVisibility(View.VISIBLE);
                        AfterSaleDetailActivity.this.mPhotoView.animaFrom(AfterSaleDetailActivity.this.mInfo);
                    }

                });
            }
        });
    }

    protected void onCreate(Bundle paramBundle) {
        super.onCreate(paramBundle);
        setContentView(R.layout.activity_after_sale_detail);
        this.orderId = getIntent().getIntExtra("orderId", -1);
        ButterKnife.bind(this);
        this.userId = getSharedPreferences("JLAppData", 0).getInt("userId", -1);
        buildProgressDialog();
        init();
    }

    public boolean onKeyDown(int paramInt, KeyEvent paramKeyEvent) {
        if ((paramInt == 4) && (paramKeyEvent.getRepeatCount() == 0)) {
            if (this.parentPhotoView.getVisibility() == View.VISIBLE) {
                this.parentPhotoView.setVisibility(View.GONE);
                this.parentDetail.setVisibility(View.VISIBLE);
            }else  {
                finish();
                return true;
            }
        }
        return super.onKeyDown(paramInt, paramKeyEvent);
    }

    protected void onResume() {
        super.onResume();
        this.parentDetail.setVisibility(View.VISIBLE);
        this.parentPhotoView.setVisibility(View.GONE);
    }

    public void setAdapter() {
        CustomLanearLayoutManager localCustomLanearLayoutManager = new CustomLanearLayoutManager(this);
        localCustomLanearLayoutManager.setScrollEnabled(false);
        this.recyclerView.setLayoutManager(localCustomLanearLayoutManager);
        this.goodsListAdapter = new AfterSaleDetailGoodsListAdapter(R.layout.after_sale_detail_goods_list_item, this.orderDetailsBeanList);
        this.recyclerView.setAdapter(this.goodsListAdapter);
    }
}


/* Location:              /Users/davidzhang/Documents/decompileApk/jlfood-dex2jar.jar!/com/jl/jlapp/mvp/activity/AfterSaleDetailActivity.class
 * Java compiler version: 6 (50.0)
 * JD-Core Version:       0.7.1
 */